package com.platform.modules.mall.activity.restrict;


import com.platform.common.exception.BusinessException;
import com.platform.modules.mall.entity.MallActivityEntity;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class RestrictFactory {

    @Resource
    private WhitelistLevelVerify whitelistLevelVerify;
    @Resource
    private WhitelistNumberVerify whitelistNumberVerify;
    @Resource
    private NoRestrictVerify noRestrictVerify;

    public RestrictInterface getRestrict(MallActivityEntity activity){
        if (ConfineType.LEVEL_CONFINE.getType().equals(activity.getWhitelistConfine())){
            return whitelistLevelVerify;
        }else if (ConfineType.NUMBER_CONFINE.getType().equals(activity.getWhitelistConfine())){
            return whitelistNumberVerify;
        }else if (ConfineType.NO_CONFINE.getType().equals(activity.getWhitelistConfine())){
            return noRestrictVerify;
        }
        throw new BusinessException("没有对应的规则,请在活动配置规则");
    }

    private enum ConfineType{
        /**
         * 无限制
         */
        NO_CONFINE(0),
        /**
         * 白名单等级规则
         */
        LEVEL_CONFINE(1),
        /**
         * 白名单数量规则
         */
        NUMBER_CONFINE(2);

        private Integer type;
        ConfineType(Integer type){
            this.type=type;
        }
        public Integer getType(){
            return this.type;
        }
    }
}
